package cn.cxyxj.code_auth_jwt_persistence_prod.config;

import cn.cxyxj.code_auth_jwt_persistence_prod.auth.service.impl.RedisAuthorizationCodeServices;
import cn.cxyxj.code_auth_jwt_persistence_prod.auth.service.impl.RedisClientDetailsService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.oauth2.provider.code.JdbcAuthorizationCodeServices;
import org.springframework.security.oauth2.provider.code.RandomValueAuthorizationCodeServices;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * @author mall
 * @date 2018/12/12
 */
@Configuration
public class ClientDetailsConfig {

    @Resource
    private DataSource dataSource;

    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    /**
     * 声明 ClientDetails 实现
     */
    @Bean
    public RedisClientDetailsService redisClientDetailsService() {
        RedisClientDetailsService redisClientDetailsService = new RedisClientDetailsService(dataSource);
        redisClientDetailsService.setRedisTemplate(redisTemplate);
        return redisClientDetailsService;
    }

    @Bean
    public RandomValueAuthorizationCodeServices authorizationCodeServices() {
//        RedisAuthorizationCodeServices redisAuthorizationCodeServices = new RedisAuthorizationCodeServices();
//        redisAuthorizationCodeServices.setRedisTemplate(redisTemplate);
//        return redisAuthorizationCodeServices;
        return new JdbcAuthorizationCodeServices(dataSource);
    }

}
